#include "Flag.h"

Slide* Flag::black = NULL;
Slide* Flag::blue = NULL;
Slide* Flag::green = NULL;
Slide* Flag::yellow = NULL;

Flag::Flag(char type, Point<float> pos) : MovingSprite() {
	loadBitmap();

	ani->go();
	if(type == 1)
		ani->setSlide(black, .15);
	else if(type == 2)
		ani->setSlide(blue, .17);
	else if(type == 3)
		ani->setSlide(green, .19);
	else if(type == 4)
		ani->setSlide(yellow, .19);

	this->start(pos);
}

void Flag::loadBitmap() {
	if(black != NULL)
		return;

	black = new Slide();
	blue = new Slide();
	green = new Slide();
	yellow = new Slide();

	black->image = al_load_bitmap("rsc/Objects/Flag/Black.tga");
	al_convert_mask_to_alpha(black->image, al_map_rgb(106, 76, 48));
	black->slideWidth = 64;
	black->slideHeight = 96;
	black->numSlides = 9;
	blue->image = al_load_bitmap("rsc/Objects/Flag/Blue.tga");
	al_convert_mask_to_alpha(blue->image, al_map_rgb(106, 76, 48));
	blue->slideWidth = 64;
	blue->slideHeight = 96;
	blue->numSlides = 9;
	green->image = al_load_bitmap("rsc/Objects/Flag/Green.tga");
	al_convert_mask_to_alpha(green->image, al_map_rgb(106, 76, 48));
	green->slideWidth = 64;
	green->slideHeight = 96;
	green->numSlides = 9;
	yellow->image = al_load_bitmap("rsc/Objects/Flag/Yellow.tga");
	al_convert_mask_to_alpha(yellow->image, al_map_rgb(106, 76, 48));
	yellow->slideWidth = 64;
	yellow->slideHeight = 96;
	yellow->numSlides = 9;
}

void Flag::update() {}

void Flag::draw(Point<float> camPos) {
	al_draw_bitmap(ani->getImage(), pos.x - camPos.x, pos.y - camPos.y, 0);
}

void Flag::deleteImages() {
	if(black == NULL)
		return;

	al_destroy_bitmap(black->image);
	al_destroy_bitmap(blue->image);
	al_destroy_bitmap(yellow->image);
	al_destroy_bitmap(green->image);

	delete black;
	delete blue;
	delete yellow;
	delete green;

	black = NULL;
}